﻿using System.Web.UI;
using Cms.Application;
using Cms.Domain;
using Cms.Domain.RepositoryInterfaces;
using Cms.Web.Framework.Controls;

namespace Cms.Web.Framework.DashboardGadgets
{
    public abstract class BaseGadget : UserControl, ITranslatable
    {
        private DashboardGadget _gadget;

        public DashboardGadget Gadget
        {
            get { return _gadget; }
            set { _gadget = value; }
        }

        public Administrator Administrator { get; set; }

        public IRepositoryFactory RepositoryFactory { get; set; }

        #region ITranslatable Members

        public string ContextTranslationFile
        {
            get { return "Admin/Translations/DashboardGadgets/" + _gadget.GetFilenameWithoutExtension() + ".xml"; }
        }

        public string Localization
        {
            get { return ((AdminBasePage)Page).Localization; }
        }

        #endregion

        protected string GetText(string key)
        {
            return Translator.GetText(ContextTranslationFile, key, Localization);
        }
    }
}